package work.tree;

import work.TreeNode;

public class Problem543 {
    int ans = 0;

    public int diameterOfBinaryTree(TreeNode root) {
        getDepth(root);
        return ans;

    }

    int getDepth(TreeNode root) {
        if (root == null) return 0;
        int depth1 = getDepth(root.left);
        int depth2 = getDepth(root.right);
        ans = Math.max(depth1+depth2,ans);
        return Math.max(depth2, depth1) + 1;
    }
}
